package me.zhengjie.modules.website.service.impl;

import me.zhengjie.modules.website.domain.ReservationType;
import me.zhengjie.modules.website.repository.ReservationTypeRepository;
import me.zhengjie.modules.website.repository.ReservationTypeSpecifications;
import me.zhengjie.modules.website.service.ReservationTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import me.zhengjie.modules.website.domain.PageResult;

import java.util.List;

/**
 * @author system
 * @since 2024-12-20 22:31:05
 */
@Service
public class ReservationTypeServiceImpl implements ReservationTypeService {

    @Autowired
    private ReservationTypeRepository reservationTypeRepository;

    @Override
    public PageResult<ReservationType> findPage(ReservationType reservationType, Pageable pageable) {
        Page<ReservationType> page = reservationTypeRepository.findAll(ReservationTypeSpecifications.queryList(reservationType), pageable);
        PageResult<ReservationType> result = new PageResult();
        result.setContent(page.getContent());
        result.setTotalElements(page.getTotalElements());
        return result;
    }

    @Override
    public List<ReservationType> findList(ReservationType reservationType) {
        return reservationTypeRepository.findAll(ReservationTypeSpecifications.queryList(reservationType));
    }

    @Override
    public ReservationType findById(Long id) {
        return reservationTypeRepository.findById(id).orElse(null);
    }

    @Override
    public ReservationType insert(ReservationType reservationType) {
        return reservationTypeRepository.save(reservationType);
    }

    @Override
    public ReservationType update(ReservationType reservationType) {
        return reservationTypeRepository.saveAndFlush(reservationType);
    }

    @Override
    public void delete(Long id) {
        reservationTypeRepository.deleteById(id);
    }

}